package app.fugema.shop.helper;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.base.common.utils.UIUtils;
import app.fugema.shop.constants.AppConstants;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;

import java.util.List;

public class QQHelper {
    private static QQHelper mInstance;
    private Tencent mTencent;

    public static QQHelper newInstance() {
        if (mInstance == null) {
            mInstance = new QQHelper();
        }

        return mInstance;
    }

    private QQHelper() {
        if (mTencent == null) {
            mTencent = Tencent.createInstance(AppConstants.AppKey.QQAppId, UIUtils.getContext());
        }
    }

    public void login(Activity activity, IUiListener listener) {
        String scope = "all";
        mTencent.login(activity, scope, listener);
    }

    public static boolean isQQAvilible(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage("com.tencent.mobileqq");
            List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);

            if (list.size() > 0) {
                return true;
            }
        } catch (Exception e) {

        }
        return false;
    }

}
